package com.hylanda.va.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.alibaba.fastjson.JSON;
import com.hylanda.va.entity.ClockingIn;
import com.hylanda.va.model.ClockingInQo;
//import com.hylanda.va.service.ClockingInService;

@Controller
@RequestMapping("/clockingIn")
public class ClockingInController {
    private static Logger logger = LoggerFactory.getLogger(ClockingInController.class);

//    @Autowired
//    private ClockingInService clockingInService;
    private static final String prefix = "va/";
    @RequestMapping("/index")
    public String index() throws Exception{
        return prefix+"clockingIn/index";
    }

    @RequestMapping(value="/{id}")
    public String show(ModelMap model,@PathVariable Integer id) {
//        ClockingIn clockingIn = clockingInService.findById(id);
//        model.addAttribute("clockingIn",clockingIn);
        return prefix+"clockingIn/show";
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Page<ClockingIn> getList(ClockingInQo clockingInQo) {
    	Page<ClockingIn> page=null;
        try {
//        	page=clockingInService.findPage(clockingInQo);
//        	System.out.println(JSON.toJSONString(page.getContent()));
            return page;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/new")
    public String create(ModelMap model,ClockingIn clockingIn){
        return prefix+"clockingIn/new";
    }

    @RequestMapping(value="/save", method = RequestMethod.POST)
    @ResponseBody
    public String save(ClockingIn clockingIn) throws Exception{
//        clockingInService.create(clockingIn);
        logger.info("新增->ID="+clockingIn.getId());
        return "1";
    }

    @RequestMapping(value="/edit/{id}")
    public String update(ModelMap model,@PathVariable Integer id){
//        ClockingIn clockingIn = clockingInService.findById(id);
//        model.addAttribute("clockingIn",clockingIn);
        return prefix+"clockingIn/edit";
    }

    @RequestMapping(method = RequestMethod.POST, value="/update")
    @ResponseBody
    public String update(ClockingIn clockingIn) throws Exception{
//        clockingInService.update(clockingIn);
        logger.info("修改->ID="+clockingIn.getId());
        return "1";
    }

    @RequestMapping(value="/delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable Integer id) throws Exception{
//        clockingInService.delete(id);
        logger.info("删除->ID="+id);
        return "1";
    }

}
